﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using QLACQUY.DTO;
using System.Data;

namespace QLACQUY.DAO
{
    class NhaSanXuatDAO:DataAccess
    {
        public IList layDanhSach()
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.DataConnection();
            string strSQL = "select * from NHA_SAN_XUAT";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            OleDbDataReader dr = cmd.ExecuteReader();
            ArrayList list = new ArrayList();
            while (dr.Read())
            {
                NhaSanXuatDTO nsx = new NhaSanXuatDTO();
                nsx.Ma = (int)dr["MaNSX"];
                nsx.TenNSX = (string)dr["TenNSX"];
                list.Add(nsx);
            }
            dr.Close();
            cn.Close();
            return list;

        }
        public DataTable layBang()
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.DataConnection();
            string strSQL = "select * from NHA_SAN_XUAT";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
            DataTable tb = new DataTable();
            adapter.Fill(tb);
            return tb;
        }
        public int themNhaSanXuat(NhaSanXuatDTO dto)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.DataConnection();
            string strSQL = "insert into NHA_SAN_XUAT(TenNSX) values(?)";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            cmd.Parameters.Add("@TenNSX", OleDbType.WChar);
            cmd.Parameters["@TenNSX"].Value = dto.TenNSX;
            try
            {
                cmd.ExecuteNonQuery();
                return 1;
            }
            catch (System.Exception ex)
            {
            	return 0;
            }            
        }

    }
}
